home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Newbie needs help w/ARGV ARGC
- Date: 25 Mar 1996 12:16:25 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4j62qp$fnj@sparcserver.lrz-muenchen.de>
- References: <4j4ja1$dc3@mtinsc01-mgt.ops.worldnet.att.net>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- dslayer@worldnet.att.net (Raymond Joh) writes:
-
- >I have spent three days attempting to determine why my command line
- >arguments are failing...
-
- >I am using MS Quick C 2.5
-
- >I just want to be able to enter two file paths at the command line.
- >Here is my code:
-
- >#include <stdio.h>
- >#include <stdlib.h>
-
-
- >main(int argc, char *argv[],char *envp[])
-
- 1) Implicit "int" can be avoided, and should be avoided imho.
- 2) Since you don't _need_ "envp", and since it makes this
- program less portable, I wonder why you use it.
-
- >{
- >FILE *ofp,*nfp;
- >char ch;
-
- >gets(*argv);
-
- What is this supposed to do? "*argv" could be the name of your
- program, and it is _not_ a string variable you should use in
- your program. If you want to read a string as the first action of
- your program, why not replace this line with:
-
- char line[BIG_ENOUGH];
-
- fgets(line, sizeof line, stdin);
-
-
- >if (argc!=3)
- > {
- > printf("Enter: <source> <destination>\n");
- > exit(1);
- > }
-
- >Code countinues but when I enter my command line input such as:
-
- >A:\readme.txt A:\newfile.txt
-
- Let us assume that your program is called "cp". If you enter
- "cp readme.txt newfile.txt" at your shell prompt, main will
- be called with
-
- argc: 3
- argv: { "cp", "readme.txt", "newfile.txt", NULL }
-
- in a lot of environments. The exact value of "argv[0]" and both
- the existence and contents of "argv[3]" might vary on your system.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-